#include<unistd.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<errno.h>
#include<fcntl.h>


/*获取温度*/
float get_temperature(float *T_temperature)
{

	int 			fd;
    char    		buf[512];
    char    		*ptr;
	float			a;


        fd=open("/sys/bus/w1/devices/28-0317320a8aff/w1_slave",O_RDONLY);
        memset(buf,0,sizeof(buf));//buf初始化
        read(fd,buf,sizeof(buf));
        //printf("buf:%s\n",buf);

        ptr=strstr(buf,"t=");
        if(!ptr)
        {
                printf("can not find t= string\n");
                return -1;
        }
        ptr+=2;
        a=atof(ptr);
	*T_temperature=(a/1000);
        //printf("ptr: %s\n",ptr);
        printf("T_temperature:%f\n",*T_temperature);
        close(fd);
	return 0;	
}
